package org.dromara.gateway.config;

import com.alibaba.cloud.nacos.NacosConfigManager;
import lombok.Data;
import org.dromara.gateway.config.properties.DynamicRouteProperties;
import org.dromara.gateway.route.NacosRouteDefinitionRepository;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 动态路由配置类
 *
 * @author shuai.zhou
 */
@Data
@Configuration
@ConditionalOnProperty(value = "dynamic.nacos.enabled", havingValue = "true")
@EnableConfigurationProperties(DynamicRouteProperties.class)
public class DynamicRouteConfig {

    @Bean
    public NacosRouteDefinitionRepository nacosRouteDefinitionRepository(NacosConfigManager nacosConfigManager, DynamicRouteProperties dynamicRouteProperties) {
        return new NacosRouteDefinitionRepository(nacosConfigManager, dynamicRouteProperties);
    }

}
